package com.googlecode.cswish.struts.spring;

import java.util.List;

import com.googlecode.cswish.model.PageElements;
import com.googlecode.cswish.model.PageInfo;
import com.googlecode.cswish.model.Reference;
import com.googlecode.cswish.oosearch.Condition;
import com.googlecode.cswish.oosearch.QLInfo;

/**
 * It provides the generic business operations
 * 
 * @author Jerry.feng
 */
public interface GenericService {
	/**
     * Search one page of data
     * 
     * @param model
     * @param pageNo
     * @param newSearch
     * @return
     */
    public <T> PageInfo<T> search(T model, String keywords, 
    		int start, int limit, String sort, String dir, boolean newSearch,
    		Reference<QLInfo> qlInfoRef, PageElements ps);
    
    public <T> QLInfo buildQlInfo(T model, String keywords, int start, int limit, String sort, String dir,
			boolean newSearch, Reference<QLInfo> qlInfoRef, PageElements ps);
    
    /**
     * Convert model to QL expression and return the table result
     * 
     * @param model
     * @param condition
     * @return
     */
    public <T> PageInfo<T> searchByModel(T model, Condition condition);
    
    /**
     * search all the data result
     * 
     * @param model
     * @return
     */
    public <T> PageInfo<T> searchAll(T model);
    
    /**
     * calculate the record count
     * 
     * @param qlInfo
     * @return
     */
    public int getCount(QLInfo qlInfo, boolean cacheable);
    
    public PageInfo searchByQl(QLInfo qlInfo, boolean cacheable);
    
    public <T> T add(T model);
    
    public <T> List<T> addList(List<T> model);
    
    public void update(Object model);
    
    public <T> T merge(T model);
    
    public void updateList(List<Object> model);

    public boolean delete(Object model);
    
    public boolean deleteList(List<Object> model);
    
    public <T> T view(T model);

    public <T> T load(T model);
}